<?php

use Illuminate\Http\Request;

/*
|--------------------------------------------------------------------------
| USER Routes
|--------------------------------------------------------------------------
|
| Here is where you can register API routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| is assigned the "api" middleware group. Enjoy building your API!
|
*/

/**
 * 路由
 * http://backend.manager.my/api/agency/users
 */

Route::post('/login', 'Agency\LoginController@login')->name('login.login');

Route::post('/token/refresh', 'Agency\LoginController@login')->name('login.refresh');

Route::middleware('auth:agency','scopes:agency_base')->group(function() {
	Route::post('/logout', 'Agency\LoginController@logout')->name('login.logout');

    Route::middleware('auth:agency','scope:agency_info_all')->group(function() {
        /**
         * 获取登录用户详细信息
         */
        Route::get('/users', function (Request $request) {
            return response()->json([
                'status' => 'success',
                'status_code' => 200,
                'data' => $request->user()
            ],200);
        });
    });


    Route::middleware('auth:agency','scope:agency_info_base,agency_info_all')->group(function() {
        /**
         * 获取登录用户基本信息
         */
        Route::get('/info', function (Request $request) {
            $user = $request->user(); // Returns an instance of `Admin` or `User`
            return response()->json([
                'status' => 'success',
                'status_code' => 200,
                'data' => [
                    'name' => $user['name'],
                    'email' => $user['email']
                ]
            ],200);
        });
    });

});